package com.example.dto;

import java.time.Duration;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.security.oauth2.jose.jws.SignatureAlgorithm;
import org.springframework.security.oauth2.server.authorization.settings.OAuth2TokenFormat;



@Data
public class TokenSettingsDTO {
    @Schema(
            description = "设置是否重用刷新令牌",
            required = true,
            example = "true",
            defaultValue = "true"
    )
    private Boolean reuseRefreshTokens;

    @Schema(
            description = "ID Token 签名算法",
            example = "RS256",
            defaultValue = "RS256"
    )
    @JsonSerialize(using = SignatureAlgorithmSerializer.class)
    @JsonDeserialize(using = SignatureAlgorithmDeSerializer.class)
    private SignatureAlgorithm idTokenSignatureAlgorithm;

    @Schema(
            description = "访问令牌的有效期（秒）",
            example = "43200",
            defaultValue = "43200"
    )
    @JsonSerialize(using = DurationSerializer.class)
    @JsonDeserialize(using = DurationDeserializer.class)
    private Duration accessTokenTimeToLive;

    @Schema(
            type = "string", // 强制类型
            description = "访问令牌的格式",
            example = "self-contained",
            defaultValue = "self-contained"
    )
    @JsonSerialize(using = OAuth2TokenFormatSerializer.class)
    @JsonDeserialize(using = OAuth2TokenFormatDeserializer.class)
    private OAuth2TokenFormat accessTokenFormat;

    @Schema(
            description = "刷新令牌的有效期（秒）",
            example = "604800",
            defaultValue = "604800"
    )
    @JsonSerialize(using = DurationSerializer.class)
    @JsonDeserialize(using = DurationDeserializer.class)
    private Duration refreshTokenTimeToLive;

    @Schema(
            description = "授权码的有效期（秒）",
            example = "300",
            defaultValue = "300"
    )
    @JsonSerialize(using = DurationSerializer.class)
    @JsonDeserialize(using = DurationDeserializer.class)
    private Duration authorizationCodeTimeToLive;

    @Schema(
            description = "设备码的有效期（秒）",
            example = "300",
            defaultValue = "300"
    )
    @JsonSerialize(using = DurationSerializer.class)
    @JsonDeserialize(using = DurationDeserializer.class)
    private Duration deviceCodeTimeToLive;
}